/*
 * $Id: AddEditAOItemExchange.java 28 2013-05-21 12:11:22Z antonyhands@gmail.com $
 */
package ru.olympus.antonyhands.ao.ui;

import java.util.List;

import ru.olympus.antonyhands.ao.UIHelper;
import ru.olympus.antonyhands.ao.data.AOData;
import ru.olympus.antonyhands.ao.data.entities.AOItem;
import ru.olympus.antonyhands.ao.data.util.ByTitleComparator;
import ru.olympus.antonyhands.ao.ui.helper.ResourcesTableHelper;
import ru.olympus.antonyhands.ao.ui.listener.CancelButtonClickListener;
import ru.olympus.antonyhands.ao.util.GoogleIterable;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

/**
 * Компонент для добавления/редактирования обмена предметов
 * 
 * @author AntonyHands
 * @since 21.05.2013
 */
public class AddEditAOItemExchange extends CustomComponent
{
    private static final long serialVersionUID = -3492883044086440863L;

    private VerticalLayout mainLayout;
    private Table _resources;
    private ComboBox _itemComboBox = new ComboBox("Результирующий предмет");
    private TextField _quantity = new TextField("Количество");

    public AddEditAOItemExchange()
    {
        setCompositionRoot(buildMainComponent());
    }

    private Component buildMainComponent()
    {
        mainLayout = new VerticalLayout();

        _resources = ResourcesTableHelper.createResourcesTable();
        mainLayout.addComponent(_resources);

        List<AOItem> list = GoogleIterable.with(AOData.getInstance().listItems()).sort(new ByTitleComparator()).toArrayList();
        UIHelper.refillSelect(_itemComboBox, list);
        mainLayout.addComponent(_itemComboBox);

        _quantity.setValue("1");
        mainLayout.addComponent(_quantity);

        Button okButton = new Button("OK");
        okButton.addListener(getOkButtonListener());
        mainLayout.addComponent(okButton);

        Button cancelButton = new Button("OK");
        cancelButton.addListener(new CancelButtonClickListener());
        mainLayout.addComponent(cancelButton);

        return mainLayout;
    }

    private ClickListener getOkButtonListener()
    {
        return null;
    }
}
